<?php

namespace apiend\modules\user\controllers;

use Yii;
use apiend\components\Controller;
use common\models\user\UserSignin;

/**
 * 用户签到
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class SigninController extends Controller {

    /**
     * @inheritdoc
     */
    protected function rules() {
        return [
            [
                'allow' => true,
                'roles' => ['@'],
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    protected function verbs() {
        return [
            '*' => ['GET'],
        ];
    }

    /**
     * 检测当前用户是否已签到
     * @inheritdoc
     */
    public function actionCheck() {
        $model = UserSignin::findOne(['user_id' => $this->uid]);
        if ($model) {
            $signDatetime = time();
            if (date('Y-m-d', $model->last_time) === date('Y-m-d', $signDatetime)) {
                return true;
            }
        }
        return false;
    }

}
